package logic;

public class English implements Language {
	String[] letters = null;
	
	public English()
	{
		letters = new String[25];
		letters[0] = "a";
		letters[1] = "b";
		letters[2] = "c";
		letters[3] = "d";
		letters[4] = "e";
		letters[5] = "f";
		letters[6] = "g";
		letters[7] = "h";
		letters[8] = "i";
		letters[9] = "k";
		letters[10] = "l";
		letters[11] = "m";
		letters[12] = "n";
		letters[13] = "o";
		letters[14] = "p";
		letters[15] = "q";
		letters[16] = "r";
		letters[17] = "s";
		letters[18] = "t";
		letters[19] = "u";
		letters[20] = "v";
		letters[21] = "w";
		letters[22] = "x";
		letters[23] = "y";
		letters[24] = "z";
		
	}
	
	@Override
	public String doMappings(String text) {
		text = text.toLowerCase();
		text = text.replace(new String("j"), new String("i"));
		
		if(text.length() > 1)
		{
			for(int i = 0; i < text.length() - 1; i += 1)
				if(text.substring(i,i+1).equals(text.substring(i+1,i+2)))
					text = text.replace(text.substring(i,i+1) + text.substring(i,i+1),
							text.substring(i,i+1) + "x" + text.substring(i,i+1));
		}
		if(text.length() % 2 == 1) text += "x";
				 
		return text;
	}

	@Override
	public String[] getLetters() {
		return letters;
	}

	@Override
	public String getLetter(int n) {
		if(n >= 0 && n < 25)
			return letters[n];
		else
			return null;
	}

	@Override
	public boolean isValidLetter(String l) {
		l = l.toLowerCase();
		for(String s : letters) if(s.equals(l)) return true;
		return false;
	}

}
